home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACSHELL
/
MS1
/
SHELL_SO
/
PATHEXPA.C
< prev
next >
Wrap
Text File
|
1992-12-02
|
11KB
|
484 lines
/*
* MacShell Source File
*
* Copyright (c) 1989, 1990, 1991, 1992 Suick Bay Technologies. All rights reserved.
*
*
* RESTRICTIONS ON MacShell program and source code.
*
* Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
* restricted use by the owner of the CDROM "Disk to the future II".
*
* Ñ╩No permission is granted for any commercial use without the written
* consent of the Suick Bay Technologies.
*
* Ñ╩No permission is granted for any redistribution of any kind use without
* the written consent of the Suick Bay Technologies.
*
* Ñ╩Permission is granted to use this for any personal noncommercial use.
*
* Ñ╩You may not distribute source or executable code at all, nor may you
* distribute it with or within a commercial product without the written
* consent of the Suick Bay Technologies. Please send modifications to
* the author for inclusion in updates to the program. Thanks.
*
*
* MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
* OR ANY PART THEREOF.
*
* In no event will Suick Bay Technologies be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Suick Bay Technologies has been advised of the possibility of such damages.
*
* Suick Bay Technologies can be reached at:
*
* 8768 Cottonwood lane
* Maple Grove, MN 55369
* Voice: (612) 425-7025
* AppleLink: D5233
*
*
* No parts of this software may be reproduced or stored in a
* retrieval system or transmitted in any form, or any means,
* electronic, mechanical, photocopying, recording or otherwise,
* without the prior written permission of Suick Bay Technologies.
*
* Spread the word and not the disk.
*
* SPK 030190 : Update for Mac, DOS paths
* SPK 012290 : Initial
*/
#include "System.h"
#include "Global.h"
#include "Mac.h"
#include "Path.h"
#include "Prefs.h"
#include <FileMgr.h>
#include <HFS.h>
/*******************************************************************
*
* ExpandPath takes a path pattern and expands it to all of its
* possible values. For each match that it makes it calls the
* callBack procdure in the following format
*
* callBack( WHandle ShellWh, int ProcID, char *path, char *last,
* pathType what, int vRefNum, long dirID );
*
* if what == pathIsDir then
* path is the dirs name
* vRefNum and dirID are for the dir
*
* if what == pathIsFile then
* path is the file name
* vRefNum and dirID are for the dir of the file
*
*******************************************************************/
/* move these to shell data object */
char expanded[ 256 ]; /* the expanded pathname */
int16 matches; /* number matches to the current path */
Boolean abortSearch = FALSE;
Boolean scanFwd = TRUE;
OsType scanTYPE = 0L,
scanCREA = 0L;
char strTYPE[ 8 ],
strCREA[ 8 ];
void ScanExpFwd( Boolean forward )
{
scanFwd = forward;
}
void ScanForTYPE( OsType type )
{
scanTYPE = type;
TypeToStr( type, strTYPE );
}
void ScanForCREA( OsType creator )
{
scanCREA = creator;
TypeToStr( creator, strCREA );
}
void ScanInit()
{
scanFwd = TRUE;
scanTYPE = 0L;
scanCREA = 0L;
}
Boolean ExpandCheck( OsType type, OsType creator )
{
if( scanTYPE || scanCREA )
{
if( scanTYPE && (scanTYPE != type ))
{
char str[ 8 ];
TypeToStr( type, str );
if( StrPatMatch( str, strTYPE ) == FALSE )
return( FALSE );
}
if( scanCREA && (scanCREA != creator ))
{
char str[ 8 ];
TypeToStr( creator, str );
if( StrPatMatch( str, strCREA ) == FALSE )
return( FALSE );
}
}
return( TRUE ); /* no finder check */
}
/*******************************************************************/
void ExpandDirPath( WHandle ShellWh, int16 ProcID, char *pattern,
ProcPtr callBack, int16 vRefNum, int32 dirID )
{
int16 len, i = 0, inc, recurse = FALSE, movedUp = 0;
int32 parDirID;
char nextEntry[ 64 ], scan[ 64 ], *cp, *lastPat, *recursePat;
pathType pt;
OSErr err;
CInfoPBRec scanPB;
OsType type, creator;
if( abortSearch || UserAbort() )
{
abortSearch = TRUE;
return;
}
len = strlen( expanded );
if( *pattern == '\0' ) /* no spec */
return;
if( *pattern == ':') /* look for Mac dir separator */
{
if( *(pattern+1) == ':' ) /* look for parent spec */
while( *pattern == ':' && *(pattern+1) == ':' )
{
CursorWait();
if( err = GetParID( vRefNum, dirID, &parDirID ) )
{
FileError( err );
return;
}
dirID = parDirID;
movedUp++;
if( err = GetParID( vRefNum, dirID, &parDirID ) )
{
FileError( err );
return;
}
pattern++;
pattern++;
}
else
pattern++;
}
else
return;
if( *pattern =='\0' && callBack ) /* last spec was a dir */
{
matches++;
GetCurrMacPath( vRefNum, dirID, expanded );
(*callBack)( ShellWh, ProcID, expanded, "", pathIsDir,
vRefNum, dirID );
return;
}
lastPat = pattern;
lastPat--;
while( (*pattern != ':') && *pattern ) /* save entry */
nextEntry[i++] = *pattern++;
nextEntry[i] = '\0';
if( (strcmp( nextEntry, "..." ) == 0) || /* was it a recursive spec ? */
(strcmp( nextEntry, "╔" ) == 0) )
recurse = TRUE;
/* Get the number of items in this directory */
if( scanFwd == FALSE )
{
scanPB.dirInfo.ioFDirIndex = -1; /* this directory */
scanPB.dirInfo.ioCompletion = 0L;
scanPB.dirInfo.ioNamePtr = (StringPtr) scan;
scanPB.dirInfo.ioVRefNum = vRefNum;
scanPB.dirInfo.ioDrDirID = dirID;
err = PBGetCatInfo( &scanPB, FALSE );
i = scanPB.dirInfo.ioDrNmFls;
inc = (-1);
}
else
{
inc = 1;
i = 1;
}
while( i ) /* for each item index ... */
{
CursorWait();
if( abortSearch || UserAbort() )
{
abortSearch = TRUE;
return;
}
scanPB.hFileInfo.ioFDirIndex = i;
scanPB.hFileInfo.ioCompletion = 0L;
scanPB.hFileInfo.ioNamePtr = (StringPtr) scan;
scanPB.hFileInfo.ioVRefNum = vRefNum;
scanPB.hFileInfo.ioDirID = dirID;
err = PBGetCatInfo( &scanPB, FALSE );
if( err == fnfErr ) /* last item */
break;
else if( err )
{
FileError( err );
break;
}
type = scanPB.hFileInfo.ioFlFndrInfo.fdType;
creator = scanPB.hFileInfo.ioFlFndrInfo.fdCreator;
PtoCstr( scan );
if( recurse ) /* depth first */
{
long scanDirID = scanPB.hFileInfo.ioDirID;
char nextDown[ 256 ];
int j = 0;
recursePat = pattern;
while( *recursePat == ':')
recursePat++;
while( (*recursePat != ':') && *recursePat )
nextDown[j++] = *recursePat++;
nextDown[j] = '\0';
if( StrPatMatch( scan, nextDown ) )
{
if( scanPB.hFileInfo.ioFlAttrib & 0x10 )
{
cp = expanded + len; /* add this name to the expanded path */
*cp++ = ':'; *cp = '\0';
strcat( cp, scan );
if( *pattern )
ExpandDirPath( ShellWh, ProcID, pattern,
callBack, vRefNum, scanDirID );
else if( callBack && ExpandCheck( 'Fldr', 'Fldr' ))
{
matches++;
(*callBack)( ShellWh, ProcID, expanded, scan,
pathIsDir, vRefNum, dirID );
}
expanded[ len ] = '\0'; /* reset back to path */
}
else if( *recursePat == '\0' && callBack &&
ExpandCheck( type, creator ))
{
matches++;
(*callBack)( ShellWh, ProcID, expanded, scan,
pathIsFile, vRefNum, dirID );
}
}
else if( scanPB.hFileInfo.ioFlAttrib & 0x10 )
{
cp = expanded + len;/* add this name to the expanded path */
*cp++ = ':'; *cp = '\0';
strcat( cp, scan );
if( j == 0 )
strcpy( nextDown, "*" );
ExpandDirPath( ShellWh, ProcID, lastPat,
callBack, vRefNum, scanDirID );
expanded[ len ] = '\0'; /* reset back to path */
}
}
else if( StrPatMatch( scan, nextEntry ) )
{
if( scanPB.hFileInfo.ioFlAttrib & 0x10 ) /* was a directory */
{
long scanDirID = scanPB.hFileInfo.ioDirID;
cp = expanded + len; /* add this name to the expanded path */
*cp++ = ':';
*cp = '\0';
strcat( cp, scan );
if( *pattern )
ExpandDirPath( ShellWh, ProcID, pattern, callBack,
vRefNum, scanDirID );
else if( callBack && ExpandCheck( 'Fldr', 'Fldr' ))
{
matches++;
(*callBack)( ShellWh, ProcID, expanded, scan,
pathIsDir, vRefNum, dirID );
}
expanded[ len ] = '\0'; /* reset back to path */
}
else if( *pattern == '\0' && callBack &&
ExpandCheck( type, creator ))
{
matches++;
(*callBack)( ShellWh, ProcID, expanded, scan,
pathIsFile, vRefNum, dirID );
}
}
i += inc;
}
}
/*******************************************************************/
void ExpandVolPath( WHandle ShellWh, int16 ProcID, char *pattern,
char *path, ProcPtr callBack )
{
int16 i;
OSErr err;
HVolumeParam HPB;
char str[ 256 ];
for( i = 1; i < 10; i++ )
{
if( abortSearch || UserAbort() )
{
abortSearch = TRUE;
return;
}
HPB.ioCompletion = NULL;
HPB.ioNamePtr = (StringPtr) str;
HPB.ioVRefNum = 0;
HPB.ioVolIndex = i;
err = PBHGetVInfo( &HPB, FALSE );
if( err == nsvErr )
break;
if( err )
{
FileError( err );
break;
}
PtoCstr( str );
strcpy( expanded, str );
if( (strcmp( pattern, "..." ) == 0) || (strcmp( pattern, "╔" ) == 0) )
{
if( *path )
{
char p2[ 256 ];
p2[ 0 ] = ':'; p2[ 1 ] = '\0';
strcat( p2, pattern );
strcat( p2, path );
ExpandDirPath( ShellWh, ProcID, p2, callBack,
HPB.ioVRefNum, 2L );
}
else if( callBack && ExpandCheck( 'Fldr', 'Fldr' ))
{
matches++;
(*callBack)( ShellWh, ProcID, expanded, str,
pathIsVol, HPB.ioVRefNum, 2L );
}
}
else if( StrPatMatch( str, pattern ) )
{
if( *path )
ExpandDirPath( ShellWh, ProcID, path, callBack,
HPB.ioVRefNum, 2L );
else if( callBack && ExpandCheck( 'Fldr', 'Fldr' ))
{
matches++;
(*callBack)( ShellWh, ProcID, expanded, str,
pathIsVol, HPB.ioVRefNum, 2L );
}
}
}
}
/*******************************************************************/
int16 ExpandPath( WHandle ShellWh, int16 ProcID, char *expPattern,
ProcPtr callBack, int16 vRefNum, int32 dirID )
{
Boolean neededVol, goToRoot;
char volPattern[ 64 ],
pathPattern[ 256 ];
int32 parDirID;
CursorWait();
matches = 0;
expanded[ 0 ] = '\0';
abortSearch = FALSE;
strcpy( pathPattern, expPattern );
if( ShellPrefs.useMacOSPath )
_MacToMac( pathPattern, &neededVol, &goToRoot, volPattern );
else if( ShellPrefs.useUNIXPath )
_UNIXToMac( pathPattern, &neededVol, &goToRoot, volPattern );
else if( ShellPrefs.useDOSPath )
_DOSToMac( pathPattern, &neededVol, &goToRoot, volPattern );
if( neededVol )
{
if( vRefNum == 0 ) /* volume does not exist */
return;
ExpandVolPath( ShellWh, ProcID, volPattern, pathPattern, callBack );
}
else
{
if( goToRoot )
{
GetVol( NULL, &vRefNum );
dirID = 0;
}
ExpandDirPath( ShellWh, ProcID, pathPattern, callBack, vRefNum, dirID );
}
SetArrow();
return( matches );
}